<template>
    <div>
      <table border="1">
        <tr>
          <th>名称</th>
          <th>价格</th>
          <th>图片</th>
          <th>操作</th>
        </tr>
        <tr v-for="a in all">
          <td>{{ a.title }}</td>
          <td v-if="uid">
            {{ a.price / 2 }}

          </td>
          <td v-else>
            {{ a.price }}

          </td>
          <td><img :src="'http://localhost:8000/static/upload/'+a.img" width="50px"></td>
          <td><button @click="dian(a.id)">立即预定</button></td>
        </tr>

      </table>
    </div>
</template>

<script>
    export default {
        name: "allgoods",
      data(){
          return{
            all:[],
            uid:localStorage.getItem('uid')
          }
      },
      mounted() {
          this.axios({
            url:'http://127.0.0.1:8000/allgoods/',
            method:'post'

          }).then(res=>{
            this.all = res.data.data;
            console.log(res)
          })
      },
      methods:{
          dian(){
            if (localStorage.getItem('uid')){
              this.$router.push({'name':'show',query:{'id':this.id}})
            }else {
              this.$router.push({'name':'login'})
            }
          }
      }
    }
</script>

<style scoped>

</style>
